package com.example.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.PageResult;
import com.example.common.Result;
import com.example.dto.CategoryDeleteDTO;
import com.example.dto.CategoryPageDTO;
import com.example.entity.Category;
import com.example.service.CategoryService;
import com.example.vo.CategoryListVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 分类表 前端控制器
 * </p>
 *
 * @author wuyunbin
 * @since 2024-10-15
 */
@Slf4j
@RestController
@RequestMapping("/admin/category")
public class CategoryController {
    @Resource
    private CategoryService categoryService;

    @PostMapping("/add")
    public Result<Boolean> add(@RequestBody Category category) {
        boolean save = categoryService.save(category);
        return Result.success(save);
    }

    @PostMapping("/list")
    public PageResult<Category> list(@RequestBody CategoryPageDTO categoryPageDTO) {
        IPage<Category> page = categoryService.getPage(categoryPageDTO);
        return PageResult.success(page);
    }

    @PostMapping("/delete")
    public Result<Boolean> delete(@RequestBody Category category) {
        boolean remove = categoryService.removeById(category.getId());
        return Result.success(remove);
    }

    @PostMapping("/select/list")
    public Result<List<CategoryListVO>> selectList() {
        List<CategoryListVO> list = categoryService.getSelectList();
        return Result.success(list);
    }
}
